package cn.topevery.garden.dal.logic;

import cn.topevery.garden.dal.dao.ParkFileDao;
import cn.topevery.garden.entity.po.ParkFile;
import cn.topevery.garden.framework.base.BaseLogic;
import hw.topevery.framework.db.base.BaseEntityDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 
 *
 * @author code-generate
 * @date 2021-08-06
 */
@Service
public class ParkFileLogic extends BaseLogic<ParkFile> {
    @Autowired
    ParkFileDao parkFileDao;

    @Override
    public BaseEntityDao<ParkFile, Integer> getDao() {
        return parkFileDao;
    }


    /**
     * 描述 保存.
     *
     * @param userId    the user id
     * @param mainId    the main id
     * @param parkFiles the park files
     * @author wenzhao.lin
     * @created 2021 -08-26 09:12:11 Save or update.
     */
    public void saveOrUpdate(String userId,Integer mainId, List<ParkFile> parkFiles) {
        parkFileDao.deleteById(mainId);
        for (ParkFile parkFile : parkFiles){
            parkFile.setMainId(mainId);
            parkFileDao.saveOrUpdate(userId, parkFile);
        }

    }

    /**
     * 获取列表
     *
     * @param pid
     */
    public List<ParkFile> getListByPid(Integer pid) {
        List<ParkFile> list = parkFileDao.getListByPid(pid);
        return list;
    }

    /**
     * 描述 通过mainId删除.
     *
     * @param id the id
     * @author wenzhao.lin
     * @created 2021 -08-26 09:14:12 Delete by id.
     */
    public void deleteById(Integer id){
        parkFileDao.deleteById(id);
    }
}
